<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>ERP管理系统1.0</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

        <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/font.css">
        <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/xadmin.css">
        <script src="<%=request.getContextPath()%>/resources/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入用户名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加用户','addinput',800,600)"><i class="layui-icon"></i>添加用户</button>
                        </div>
                        
                        <div class="layui-card-body layui-table-body layui-table-main">    
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                   
                                    <th style="text-align: center;">编号</th>
                                    <th style="text-align: center;">用户名</th>
                                    <th style="text-align: center;">昵称</th>
                                    <th style="text-align: center;">性别</th>
                                    <th style="text-align: center;">年龄</th>
                                    <th style="text-align: center;">操作</th>
                                  </tr>
                                </thead>
                               
                                <tbody>
                                <!-- 动态获取内容 -->
                               	<c:choose>
                               		<c:when test="${empty users }">
                               					<td colspan="6" > 没有符合条件的数据</td>
                               		</c:when>
                               		<c:otherwise>
                               		<c:forEach items="${users }" var="user">
                                	<tr>
                                		<td>${user.id }</td>
                                		<td>${user.username }</td>
                                		<td>${user.nickname }</td>
                                		<td>
                                			<c:choose>
                                				<c:when test="${user.sex==1 }">男</c:when>
                                				<c:otherwise>女</c:otherwise>
                                			</c:choose>
                                		</td>
                                		<td>${user.age }</td>
                                		
                                			<td class="td-manage">                       
                                			<!--  ★ 点击这个按钮，如何跳转到编辑页面 路径是什么样子的 -->
                                			<!-- updateInput 传给servlet 一个 id -->
                                			<!--  转至servlet 去接收这个id -->
                                			<!--  这里做的事情是 用户在点击编辑 ，获取点的哪个数据的编辑  通过id确认 
                                			 然后告知servlet信息 存储起来  然后通过servlet跳转到（打开）编辑页面 update.jsp -->
                                			 
                                			 <!-- 点这个updateInput  等于更改路径  -->
                                      		<a title="编辑"    onclick="xadmin.open('编辑','updateInput?id=${user.id}',800,600)" >
                                        	<i class="layui-icon">&#xe642;</i>                              
                                      		<a title="删除"   onclick="member_del(this,'${user.username}')">
                                        	<i class="layui-icon">&#xe640;</i>
                                      </a>                                     
                                    </td>	
                                	</tr>
                                	</c:forEach>
                                	</c:otherwise>
                                </c:choose>
                                </tbody>                             
                           </table>
                        </div>
                        
                        <div class="layui-card-body ">
                            <div class="page">
                                <div>
                                  <a class="prev" href="">&lt;&lt;</a>
                                 <span class="current">1</span>
                                  <a class="num" href="">2</a>
                                  <a class="num" href="">3</a>
                                  <a class="next" href="">&gt;&gt;</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
	
	
    
      /*用户-删除*/
      function member_del(obj,username){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              
              // 和后端交互，删除数据库数据
              // ajax交互 到哪里去(路由) 传递的参数 回调函数
              $.post('delete',{"username":username},function(AjaxObj){
            	  // 把返回的json格式的字符串转换为json对象
            	  var json = JSON.parse(AjaxObj);
            	  // 这句话会导致删除 确认点击不关闭页面
            	  // var json = JSON.parse("tr").remove();
            	  // 删除成功 1
            	  if(json.result == 1){
            		  // 在页面中也删除这个
            		  // $(obj).parents("tr").remove();
            		  layer.msg(json.msg,{icon:1,time:1000});
            	  }else{
            		  layer.msg('删除失败!',{icon:1,time:1000});
            	  }
              })              
          });
      }


  
    </script>
</html>
